<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>C:\WorkingCopy\ColorTest\csvformat.pl.html</title>
<meta name="Generator" content="Vim/7.2">
<meta http-equiv="content-type" content="text/html; charset=Big5">
<style type="text/css">
<!--
pre { font-family: monospace; color: #000000; background-color: #ffffff; }
body { font-family: monospace; color: #000000; background-color: #ffffff; }
-->
</style>
</head>
<body>
<pre>
#!perl -w

# Time-stamp: &lt;2002/04/06, 13:12:13 (EST), maverick, csvformat.pl&gt;
# Two pass CSV file to table formatter

$delim = $#ARGV &gt;= 1 ? $ARGV[1] : ',';
print STDERR &quot;Split pattern: $delim\n&quot;;

# first pass
open F, &quot;&lt;$ARGV[0]&quot; or die;
while(&lt;F&gt;)
{
  chomp;
  $i = 0;
  map { $max[$_-&gt;[1]] = $_-&gt;[0] if $_-&gt;[0] &gt; ($max[$_-&gt;[1]] || 0) }
    (map {[length $_, $i++]} split($delim));
}
close F;

print STDERR 'Field width:   ', join(', ', @max), &quot;\n&quot;;
print STDERR join(' ', map {'-' x $_} @max);

# second pass
open F, &quot;&lt;$ARGV[0]&quot; or die;
while(&lt;F&gt;)
  {
  chomp;
  $i = 0;
  map { printf(&quot;%-$max[$_-&gt;[1]]s &quot;, $_-&gt;[0]) }
    (map {[$_, $i++]} split($delim));
  print &quot;\n&quot;;
}
close F;
</pre>
</body>
</html>
